<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="../common/jspcommon.jsp"%>
<%@include file="../common/jscss.jsp"%>

<script language="javascript">
<!--
	var grid_ae = null;
	$(function(){
		grid_ae = $("#content_list").ligerGrid({
				checkbox: true,
	            columns: [
	            { display: '内容id', name: 'id', isSort : false, width: 100 },
	            { display: '标题', name: 'title',isSort : false, width: 300 },
	            { display: '摘要', name: 'summary',isSort : false, width: 450 },
	            { display: '序号', name: 'sort',isSort : false, width: 50, editor: { type: 'text' }},
	            { display: '顺序', name: 'sort',isSort : false, width: 150,
	            	render: function (record, rowindex, value, column){
						var html = '<a onclick="updateSort(1,'+record.id+','+value+')" href="javascript:;">上移</a>'+
								   '&nbsp;&nbsp;<a onclick="updateSort(2,'+record.id+','+value+')" href="javascript:;">下移</a>'+
								   '&nbsp;&nbsp;<a onclick="updateSort(3,'+record.id+','+value+')" href="javascript:;">置顶</a>'; 
						return html;
					}
	            },
	            {
	            	display: '操作选项', 
	            	name: 'id',
	            	isAllowHide: false, 
	            	isSort : false,
	            	width :　200,
					render: function (record, rowindex, value, column){
						var html = '<a onclick="deleteContent('+value+')" href="javascript:;">删除</a>'+
									'&nbsp;&nbsp;<a onclick="editContent('+value+')" href="javascript:;">编辑</a>'; 
						return html; 
					}
	            }
	            ], 
	            pageSize:10,
	            root :'list',
	            record:'totalRecord',
	            url: "/misc/cms/getBackContent.htm?channelId=${channelId}", 
	            width: '99%',height:'99%',enabledEdit: true,
	            isChecked: f_isChecked, onCheckRow: f_onCheckRow, onCheckAllRow: f_onCheckAllRow,
	            toolbar: { items: [
                      { text: '增加', click: openAddContent, icon: 'add' },
                      { line: true },
                      { text: '删除', click: batchDelete, icon: 'delete' },
                      { line: true },
                      { text: '保存排列顺序', click: saveSort, icon: 'save' }
                      ]
                      }
	        });
	});
	function openAddContent(){
		dialog_ae = $.ligerDialog.open({ height: 830,width:900, url: "/misc/cms/toAddContent.htm?channelId=${channelId}", isResize: true ,modal:true,title:'添加内容'});
	}
	//删除内容
	function deleteContent(id){
		$.ligerDialog.confirm('你真的要删除吗？', 
				function (yes){
					if(yes){
						$.post("/misc/cms/deleteContent.htm",{contentId : id},function(data){
							if(data=="success"){
								$.ligerDialog.success("删除成功！");
								loadDate();
							}else{
								$.ligerDialog.warn("系统有点抽经，请稍候重试！");
							}
						}); 
					}
				});
	}
	function editContent(id){
		dialog_ae = $.ligerDialog.open({ height: 830,width:900, url: "/misc/cms/editContent.htm?id="+id, isResize: true ,modal:true,title:'编辑内容'});
	}
	//批量删除内容
	function batchDelete(){
		if(contentList.length==0){
			$.ligerDialog.warn("请选择删除项！");
			return;
		}
		$.ligerDialog.confirm('你真的要删除吗？', 
				function (yes){
					if(yes){
						$.post("/misc/cms/deleteContent.htm",{contentList : $.toJSON(contentList)},function(data){
							if(data=="success"){
								$.ligerDialog.success("删除成功！");
								loadDate();
							}else{
								$.ligerDialog.warn("系统有点抽经，请稍候重试！");
							}
						}); 
					}
				});
	}
	//保存排列顺序
	function saveSort(){
        var data = grid_ae.getUpdated();
        $.post("/misc/cms/saveSort.htm",{contentList : $.toJSON(data)},function(data){
			if(data=="success"){
				$.ligerDialog.success("保存成功！");
				loadDate();
			}else{
				$.ligerDialog.warn("系统有点抽经，请稍候重试！");
			}
		});
	}
	//排序(1.上移 2.下移 3.置顶)
	function updateSort(type,id,sort){
		$.post("/misc/cms/updateSort.htm",{
			type : type,
			id : id,
			sort : sort,
			channel : "${channelId}"
		},function(data){
			if(data == "success"){
				loadDate();
			}else{
				$.ligerDialog.warn("系统有点抽经，请稍候重试！");
			}
		});
	}
//-->
</script>

<div id="content_list" style="margin:0; padding:0"></div>
